package com.czxy.Demo27;


import org.apache.commons.beanutils.BeanUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

public class Test {
    public static void main(String[] args) throws DocumentException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException {
        xml();
    }
    public static void xml() throws DocumentException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, InstantiationException {
        SAXReader sa = new SAXReader();
        Document doc = sa.read("Demo27.xml");
        List<Element> elements = doc.getRootElement().elements();
        for (Element element : elements) {
            String className = element.attributeValue("className");
            Class<?> aClass = Class.forName(className);
            Object o = aClass.newInstance();
            List<Element> pro = element.elements();
            for (Element p : pro) {
                String name = p.attributeValue("name");
                String value = p.attributeValue("value");
                BeanUtils.setProperty(o , name , value);
            }
            System.out.println(o);
        }
    }
}